給自己看的筆記XD
預設會有兩個檔案
environment.ts
environment.prod.ts
平時在本機建置時(ng s)讀取的會是environment.ts
ng build => environment.ts
ng build --prod => environment.prod.ts
如果要新增環境設定檔,去angular.json => configurations 下面新增,比如叫dev
"configurations": {
"dev": {
"fileReplacements": [
<font color=#800000>酒紅色</font>
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
然後新增一個檔案取名叫做 environment.dev.ts
build的時候下參數 ng build --prod --configuration=dev
就會去吃dev的設定了